package com.example.touch.views;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;

public class TouchLayout extends LinearLayout {
   public static final String TAG = "Layout";
   public TouchLayout(Context context) {
      super(context);
   }

   public TouchLayout(Context context, @Nullable AttributeSet attrs) {
      super(context, attrs);
   }

   @Override
   public boolean onInterceptTouchEvent(MotionEvent ev) {//layout独有
      switch (ev.getAction()) {
         case MotionEvent.ACTION_DOWN:
            Log.d(TAG, "--------onInterceptTouchEvent--------down");
            break;
         case MotionEvent.ACTION_MOVE:
            Log.d(TAG, "--------onInterceptTouchEvent--------move");
            break;
         case MotionEvent.ACTION_UP:
            Log.d(TAG, "--------onInterceptTouchEvent--------up");
            break;
         case MotionEvent.ACTION_CANCEL:
            Log.d(TAG, "--------onInterceptTouchEvent--------cancel");
            break;
      }
      return false;
   }

   @Override
   public boolean dispatchTouchEvent(MotionEvent ev) {
      switch (ev.getAction()) {
         case MotionEvent.ACTION_DOWN:
            Log.d(TAG, "--------dispatchTouchEvent--------down");
            break;
         case MotionEvent.ACTION_MOVE:
            Log.d(TAG, "--------dispatchTouchEvent--------move");
            break;
         case MotionEvent.ACTION_UP:
            Log.d(TAG, "--------dispatchTouchEvent--------up");
            break;
         case MotionEvent.ACTION_CANCEL:
            Log.d(TAG, "--------dispatchTouchEvent--------cancel");
            break;
      }
      return super.dispatchTouchEvent(ev);
   }

   @SuppressLint("ClickableViewAccessibility")
   @Override
   public boolean onTouchEvent(MotionEvent event) {
      switch (event.getAction()) {
         case MotionEvent.ACTION_DOWN:
            Log.d(TAG, "--------onTouchEvent--------down");
            break;
         case MotionEvent.ACTION_MOVE:
            Log.d(TAG, "--------onTouchEvent--------move");
            break;
         case MotionEvent.ACTION_UP:
            Log.d(TAG, "--------onTouchEvent--------up");
            break;
         case MotionEvent.ACTION_CANCEL:
            Log.d(TAG, "--------onTouchEvent--------cancel");
            break;
      }
      return super.onTouchEvent(event);
   }
}
